import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home/Home.vue';
import Dashboard from '../views/Dashboard/Dashboard';
import DueToday from '../views/DueToday/DueToday';
import NewCards from '../views/NewCards/NewCards';

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    component: Home,
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: Dashboard,
        meta: {
          isKeepAlive: false,
          title: '控制台',
          pathname: '/home',
        },
      },
      {
        path: 'due-today',
        name: 'DueToday',
        component: DueToday,
        meta: {
          isKeepAlive: false,
          title: '今日学习',
          pathname: '/due-today',
        },
      },
      {
        path: 'new-cards',
        name: 'NewCards',
        component: NewCards,
        meta: {
          isKeepAlive: false,
          title: '新的学习',
          pathname: '/new-cards',
        },
      },
    ],
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/About.vue'),
  },
];

const router = new VueRouter({
  routes,
  mode: 'history',
});

export default router;
